//
//  DKOderRepayTopView.m
//  DanKU
//
//  Created by EDY on 2023/11/6.
//

#import "DKOderRepayTopView.h"
#import "DKUILabel+CustomText.h"
#import "OrderTool.h"

@interface DKOderRepayTopView()

@property(nonatomic,strong)UILabel *dk_OrderToplab;
@property(nonatomic,strong)UILabel *dk_OrderRepayLab;
@property(nonatomic,strong)UILabel *dk_OrderRepayCount;

@property(nonatomic,strong)UIView *dk_WarnCellView;
@property(nonatomic,strong)UIImageView *dk_WarnCellImg;
@property(nonatomic,strong)UILabel *dk_WarnCellcontentlab;

@property(nonatomic,strong)UIView *dk_OrderCellView;
@property(nonatomic,strong)UIImageView *dk_OrderIcon_BackImg;
@property(nonatomic,strong)UIImageView *dk_OrderIconImg;
@property(nonatomic,strong)UILabel *dk_OrderTitlelab;
@property(nonatomic,strong)UILabel *dk_OrderLine;
@property(nonatomic,strong)UILabel *dk_OrderCountlab;


//@property(nonatomic,strong)UIView *dk_UTRView;
//@property(nonatomic,strong)UITextField *dk_UTRUITextField;
//@property(nonatomic,strong)UIButton *dk_UTRButton;

@end

@implementation DKOderRepayTopView

-(instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame: frame]) {
        self.backgroundColor =  DK_Hex(@"#FAFAFA");
        [self creatUI];
    }
    return self;
}


-(void)setDataSoure:(DKOrderDetailModel *)dataSoure{
    _dataSoure = dataSoure;
    if (dataSoure.status == 180) {// 逾期还款
        self.dk_OrderRepayCount.text = [NSString stringWithFormat:@"-%@", [OrderTool formatAmountForIndia:dataSoure.repayAmount]];
    }else{
        self.dk_OrderRepayCount.text = [OrderTool formatAmountForIndia:dataSoure.repayAmount];
    }
    self.dk_OrderTitlelab.text = dataSoure.productName;
}

#pragma mark
-(void)EnterUTR{
    
    
}

-(void)creatUI{
    [self addSubview:self.dk_OrderToplab];
    [self addSubview:self.dk_OrderRepayLab];
    [self addSubview:self.dk_OrderRepayCount];
    [self addSubview:self.dk_WarnCellView];
    [self.dk_WarnCellView addSubview:self.dk_WarnCellImg];
    [self.dk_WarnCellView addSubview:self.dk_WarnCellcontentlab];

//    [self.dk_WarnCellView addSubview:self.dk_UTRView];
//    [self.dk_UTRView addSubview:self.dk_UTRUITextField];
//    [self.dk_UTRView addSubview:self.dk_UTRButton];
    
    
    [self.dk_OrderToplab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self).offset(30);
        make.right.equalTo(self).offset(-30);
        make.top.equalTo(self).offset(20);
        make.height.mas_equalTo(30);
    }];
    
    [self.dk_OrderRepayLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.height.equalTo(self.dk_OrderToplab);
        make.width.mas_equalTo(DK_SCREEN_W/2);
        make.top.equalTo(self.dk_OrderToplab.mas_bottom).offset(20);
    }];
    
    [self.dk_OrderRepayCount mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self).offset(-30);
        make.width.mas_equalTo(DK_SCREEN_W/4);
        make.bottom.equalTo(self.dk_OrderRepayLab);
        make.height.mas_equalTo(50);
    }];
    
    [self.dk_WarnCellView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self).offset(15);
        make.right.equalTo(self).offset(-15);
        make.top.equalTo(self.dk_OrderRepayCount.mas_bottom).offset(10);
        make.height.mas_equalTo(90);
    }];
    
    [self.dk_WarnCellImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.dk_WarnCellView).offset(10);
        make.top.equalTo(self.dk_WarnCellView).offset(15);
        make.height.mas_equalTo(12);
        make.width.mas_equalTo(14);
    }];
    
    [self.dk_WarnCellcontentlab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.dk_WarnCellView).offset(5);
        make.left.equalTo(self.dk_WarnCellImg.mas_right).offset(8);
        make.right.equalTo(self.dk_WarnCellView).offset(-10);
        make.bottom.equalTo(self.dk_WarnCellView).offset(-5);
        
    }];
    
//    [self.dk_UTRView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.equalTo(self.dk_WarnCellcontentlab.mas_bottom).offset(15);
//        make.left.equalTo(self.dk_WarnCellView).offset(18);
//        make.right.equalTo(self.dk_WarnCellView).offset(-18);
//        make.bottom.equalTo(self.dk_WarnCellView).offset(-15);
//    }];
//
//    [self.dk_UTRUITextField mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.bottom.equalTo(self.dk_UTRView);
//        make.left.equalTo(self.dk_UTRView).offset(10);
//        make.width.mas_equalTo(DK_SCREEN_W/2);
//    }];
//
//    [self.dk_UTRButton mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.equalTo(self.dk_UTRView).offset(5);
//        make.bottom.equalTo(self.dk_UTRView).offset(-5);
//        make.right.equalTo(self.dk_UTRView).offset(-10);
//        make.width.mas_equalTo(70);
//    }];
    
    [self addSubview:self.dk_OrderCellView];
    [self.dk_OrderCellView addSubview:self.dk_OrderIcon_BackImg];
    [self.dk_OrderCellView addSubview:self.dk_OrderIconImg];
    [self.dk_OrderCellView addSubview:self.dk_OrderTitlelab];
    [self.dk_OrderCellView addSubview:self.dk_OrderLine];
    [self.dk_OrderCellView addSubview:self.dk_OrderCountlab];
    
    [self.dk_OrderCellView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self).offset(15);
        make.right.equalTo(self).offset(-15);
        make.top.equalTo(self.dk_WarnCellView.mas_bottom).offset(10);
        make.bottom.equalTo(self);
    }];
    
    [self.dk_OrderIcon_BackImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.dk_OrderCellView).offset(15);
        make.width.height.mas_equalTo(38);
        make.top.equalTo(self.dk_OrderCellView).offset(7);
    }];
    
    [self.dk_OrderIconImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(22);
        make.height.mas_equalTo(26);
        make.center.equalTo(self.dk_OrderIcon_BackImg);
    }];

    [self.dk_OrderTitlelab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.dk_OrderIcon_BackImg.mas_right).offset(10);
        make.width.mas_equalTo(DK_SCREEN_W/4);
        make.height.mas_equalTo(30);
        make.top.equalTo(self.dk_OrderCellView).offset(10);
    }];
    
    [self.dk_OrderLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.dk_OrderCellView).offset(15);
        make.right.equalTo(self.dk_OrderCellView).offset(-15);
        make.height.mas_equalTo(0.5);
        make.top.equalTo(self.dk_OrderIcon_BackImg.mas_bottom).offset(5);
    }];

    [self.dk_OrderCountlab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.dk_OrderIcon_BackImg);
        make.width.height.equalTo(self.dk_OrderTitlelab);
        make.top.equalTo(self.dk_OrderLine.mas_bottom).offset(10);
    }];
}

#pragma mark - 懒加载

- (UILabel *)dk_OrderToplab {
    if (!_dk_OrderToplab) {
        _dk_OrderToplab = [[UILabel alloc] init];
        _dk_OrderToplab.textColor = DK_Hex(@"#333333");
        _dk_OrderToplab.font = [UIFont boldSystemFontOfSize:16];
        _dk_OrderToplab.text = @"Repay";
    }
    return _dk_OrderToplab;
}

- (UILabel *)dk_OrderRepayLab {
    if (!_dk_OrderRepayLab) {
        _dk_OrderRepayLab = [[UILabel alloc] init];
        _dk_OrderRepayLab.textColor = DK_Hex(@"#333333");
        _dk_OrderRepayLab.font = [UIFont systemFontOfSize:14];
        _dk_OrderRepayLab.text = @"Repayment amount";
    }
    return _dk_OrderRepayLab;
}

- (UILabel *)dk_OrderRepayCount {
    if (!_dk_OrderRepayCount) {
        _dk_OrderRepayCount = [[UILabel alloc] init];
        _dk_OrderRepayCount.textColor = DK_Hex(@"#333333");
        _dk_OrderRepayCount.font = [UIFont boldSystemFontOfSize:18];
        _dk_OrderRepayCount.text = @"₹ 40,000";
        _dk_OrderRepayCount.textAlignment = 2;
    }
    return _dk_OrderRepayCount;
}


-(UIView*)dk_WarnCellView{
    if (!_dk_WarnCellView) {
        _dk_WarnCellView = [[UIView alloc]init];
        _dk_WarnCellView.backgroundColor = DK_HexA(@"#FF0000", 0.05);
        _dk_WarnCellView.layer.cornerRadius = 10;
    }
    return _dk_WarnCellView;
}

- (UIImageView*)dk_WarnCellImg{
    if (!_dk_WarnCellImg) {
        _dk_WarnCellImg = [[UIImageView alloc] init];
        _dk_WarnCellImg.image =  DK_GetImage(@"dk_warning_red");
    }
    return _dk_WarnCellImg;
}

- (UILabel *)dk_WarnCellcontentlab {
    if (!_dk_WarnCellcontentlab) {
        _dk_WarnCellcontentlab = [[TTTAttributedLabel alloc] initWithFrame:CGRectZero];
        _dk_WarnCellcontentlab.textColor = DK_Hex(@"#333333");
        _dk_WarnCellcontentlab.font = [UIFont systemFontOfSize:12];
        _dk_WarnCellcontentlab.numberOfLines = 0;
//        _dk_WarnCellcontentlab.text = @"1.UPI will expire, which may lead to repayment failure. Please use the latest UPI for repayment\n2.After the transfer, please make sure to return to the app and paste Ref/UTR ";
//        [_dk_WarnCellcontentlab addColoredText:@"latest UPI" withColor:DK_Hex(@"#ED4342") andFont:[UIFont systemFontOfSize:12]];
//        [_dk_WarnCellcontentlab addColoredText:@"paste Ref/UTR" withColor:DK_Hex(@"#ED4342") andFont:[UIFont systemFontOfSize:12]];
        
        NSString *loanHead = @"1.UPI will expire, which may lead to repayment failure. Please use the latest UPI for repayment\n2.After the transfer, please make sure to return to the app and paste Ref/UTR";
        NSMutableAttributedString *attStr = [[NSMutableAttributedString alloc] initWithString:loanHead];
        [attStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:12] range:NSMakeRange(0,attStr.length)];
        [attStr addAttribute:NSForegroundColorAttributeName value:DK_Hex(@"#333333") range:NSMakeRange(0,attStr.length)];
        [attStr addAttribute:NSForegroundColorAttributeName value:DK_Hex(@"#ED4342") range:NSMakeRange(71,10)];
        [attStr addAttribute:NSForegroundColorAttributeName value:DK_Hex(@"#ED4342") range:NSMakeRange(loanHead.length-7,7)];
        _dk_WarnCellcontentlab.attributedText = attStr;
    }
    return _dk_WarnCellcontentlab;
}


//-(UIView*)dk_UTRView{
//    if (!_dk_UTRView) {
//        _dk_UTRView = [[UIView alloc]init];
//        _dk_UTRView.backgroundColor = DK_Hex(@"#FFFFFF");
//        _dk_UTRView.layer.cornerRadius = 8;
//    }
//    return _dk_UTRView;
//}
//
//
//-(UITextField*)dk_UTRUITextField {
//    if (!_dk_UTRUITextField) {
//        _dk_UTRUITextField = [[UITextField alloc] init];
//        _dk_UTRUITextField.backgroundColor = [UIColor clearColor];
//        _dk_UTRUITextField.layer.cornerRadius = 10;
//        _dk_UTRUITextField.placeholder = @"Enter UTR";
//    }
//    return _dk_UTRUITextField;
//}
//
//-(UIButton*)dk_UTRButton{
//    if (!_dk_UTRButton) {
//        _dk_UTRButton = [[UIButton alloc]init];
//        [_dk_UTRButton addTarget:self action:@selector(EnterUTR) forControlEvents:UIControlEventTouchUpInside];
//        [_dk_UTRButton setTitle:@"Submit" forState:UIControlStateNormal];
//        [_dk_UTRButton setTitleColor:DK_Hex(@"#FFFFFF") forState:UIControlStateNormal];
//        _dk_UTRButton.titleLabel.font = DK_FONT_Semibold(14);
//        [_dk_UTRButton setBackgroundColor:DK_Hex(@"#4566FF")];
//        _dk_UTRButton.layer.cornerRadius = DK_IsWidthScale(15);
//    }
//    return _dk_UTRButton;
//}
//
-(UIView*)dk_OrderCellView{
    if (!_dk_OrderCellView) {
        _dk_OrderCellView = [[UIView alloc]init];
        _dk_OrderCellView.backgroundColor = DK_Hex(@"#FFFFFF");
        _dk_OrderCellView.layer.cornerRadius = 10;
    }
    return _dk_OrderCellView;
}

- (UIImageView*)dk_OrderIcon_BackImg{
    if (!_dk_OrderIcon_BackImg) {
        _dk_OrderIcon_BackImg = [[UIImageView alloc] init];
        _dk_OrderIcon_BackImg.image =  DK_GetImage(@"dk_order_list_back_img");
    }
    return _dk_OrderIcon_BackImg;
}

- (UIImageView*)dk_OrderIconImg{
    if (!_dk_OrderIconImg) {
        _dk_OrderIconImg = [[UIImageView alloc] init];
        _dk_OrderIconImg.image =  DK_GetImage(@"dk_order_list_img");
    }
    return _dk_OrderIconImg;
}

- (UILabel *)dk_OrderTitlelab {
    if (!_dk_OrderTitlelab) {
        _dk_OrderTitlelab = [[UILabel alloc] init];
        _dk_OrderTitlelab.textColor = DK_Hex(@"#333333");
        _dk_OrderTitlelab.font = [UIFont boldSystemFontOfSize:15];
        _dk_OrderTitlelab.text = @"Go 002";
    }
    return _dk_OrderTitlelab;
}

- (UILabel *)dk_OrderLine {
    if (!_dk_OrderLine) {
        _dk_OrderLine = [[UILabel alloc] init];
        _dk_OrderLine.backgroundColor = DK_Hex(@"#E0E0E0");
    }
    return _dk_OrderLine;
}

- (UILabel *)dk_OrderCountlab {
    if (!_dk_OrderCountlab) {
        _dk_OrderCountlab = [[UILabel alloc] init];
        _dk_OrderCountlab.textColor = DK_Hex(@"#333333");
        _dk_OrderCountlab.font = [UIFont boldSystemFontOfSize:15];
        _dk_OrderCountlab.text = @"Details";
    }
    return _dk_OrderCountlab;
}


@end
